package com.djl.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.djl.ud.PlDao;
import com.djl.user.Product;

public class ProductAddServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String name = request.getParameter("productName");
		String photo = request.getParameter("photo");
		int parentId = Integer.parseInt(request.getParameter("parentId"));		
		float price = Float.parseFloat(request.getParameter("productPrice"));
		String description = request.getParameter("description");
		int stock = Integer.parseInt(request.getParameter("Stock"));
		int id = Integer.parseInt(request.getParameter("id"));
		Product product = new Product();
		product.setName(name);
		product.setFile_name(photo);
		product.setPrice(price);
		product.setDescription(description);
		product.setStock(stock);
		product.setEpc_id(parentId);
		product.setId(id);
		PlDao pl = new PlDao();
		try {
			pl.insert(product);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("ProductServlet");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request, response);
	}

}
